#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>

using namespace std;

using LL = long long;
const int N = 100010;
int n;
int x[N];

int main()
{
    scanf("%d", &n);
    for (int i = 0; i < n; i++) scanf("%d", &x[i]);
    sort(x, x + n);

    int c = x[n / 2];
    int res = 0;
    for (int i = 0; i < n; i++) res += abs(x[i] - c);

    printf("%lld\n", res);

    return 0;

}